package sample.model;

import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;

import java.util.PrimitiveIterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NmonMonitorListModel {
    //| id | 开始时间 | 频率 | 时长 | 名称 | 备注信息  |是否下载| 是否解析  | 跳转连接  |
    private SimpleStringProperty id = new SimpleStringProperty();//id
    private SimpleStringProperty startTime = new SimpleStringProperty();//时间段
    private SimpleStringProperty frequency = new SimpleStringProperty();//频率
    private SimpleStringProperty duration = new SimpleStringProperty();//时长
    private SimpleStringProperty nmonName = new SimpleStringProperty();//名称
    private SimpleStringProperty PS = new SimpleStringProperty();//备注信息
    private SimpleStringProperty isDownload = new SimpleStringProperty();//是否下载
    private SimpleStringProperty isAnalysis = new SimpleStringProperty();//是否解析
    private SimpleStringProperty toLink = new SimpleStringProperty();//跳转连接




    public NmonMonitorListModel(SimpleStringProperty id,SimpleStringProperty startTime, SimpleStringProperty frequency, SimpleStringProperty duration, SimpleStringProperty nmonName, SimpleStringProperty PS, SimpleStringProperty isDownload, SimpleStringProperty isAnalysis, SimpleStringProperty toLink) {
        this.id = id;
        this.startTime = startTime;
        this.frequency = frequency;
        this.duration = duration;
        this.nmonName = nmonName;
        this.PS = PS;
        this.isDownload = isDownload;
        this.isAnalysis = isAnalysis;
        this.toLink = toLink;
    }

    public NmonMonitorListModel(String id,String startTime, String frequency, String duration, String nmonName, String PS, String isDownload, String isAnalysis, String toLink) {
        this.id.set(id);
        this.startTime.set(startTime);
        this.frequency.set(frequency);
        this.duration.set(duration);
        this.nmonName.set(nmonName);
        this.PS.set(PS);
        this.isDownload.set(isDownload);
        this.isAnalysis.set(isAnalysis);
        this.toLink.set(toLink);
    }

    public String getId() {
        return id.get();
    }

    public SimpleStringProperty idProperty() {
        return id;
    }

    public void setId(String id) {
        this.id.set(id);
    }

    public String getStartTime() {
        return startTime.get();
    }

    public SimpleStringProperty startTimeProperty() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime.set(startTime);
    }

    public String getFrequency() {
        return frequency.get();
    }

    public SimpleStringProperty frequencyProperty() {
        return frequency;
    }

    public void setFrequency(String frequency) {
        this.frequency.set(frequency);
    }

    public String getDuration() {
        return duration.get();
    }

    public SimpleStringProperty durationProperty() {
        return duration;
    }

    public void setDuration(String duration) {
        this.duration.set(duration);
    }

    public String getNmonName() {
        return nmonName.get();
    }

    public SimpleStringProperty nmonNameProperty() {
        return nmonName;
    }

    public void setNmonName(String nmonName) {
        this.nmonName.set(nmonName);
    }

    public String getPS() {
        return PS.get();
    }

    public SimpleStringProperty PSProperty() {
        return PS;
    }

    public void setPS(String PS) {
        this.PS.set(PS);
    }

    public String getIsDownload() {
        return isDownload.get();
    }

    public SimpleStringProperty isDownloadProperty() {
//        if(isDownload.toString().toUpperCase().contains("TRUE")){
//            isDownload.set("✓");
//        }else{
//            isDownload.set("✖");
//        }
        return isDownload;
    }

    public void setIsDownload(String isDownload) {
        this.isDownload.set(isDownload);
    }

    public String getIsAnalysis() {
        return isAnalysis.get();
    }

    public SimpleStringProperty isAnalysisProperty() {
//        if(isAnalysis.toString().toUpperCase().contains("TRUE")){
//            isAnalysis.set("✓");
//        }else {
//            isAnalysis.set("✖");
//        }
        return isAnalysis;
    }

    public void setIsAnalysis(String isAnalysis) {
        this.isAnalysis.set(isAnalysis);
    }

    public String getToLink() {
        return toLink.get();
    }

    public SimpleStringProperty toLinkProperty() {
        return toLink;
    }

    public void setToLink(String toLink) {
        this.toLink.set(toLink);
    }

    public String toString(){
        String str= ResultFormat(this.id.getValue())+"\t"+
                ResultFormat(this.startTime.getValue())+"\t"+
                ResultFormat(this.frequency.getValue())+"\t"+
                ResultFormat(this.duration.getValue())+"\t"+
                ResultFormat(this.nmonName.getValue())+"\t"+
                ResultFormat(this.PS.getValue())+"\t"+
                ResultFormat(this.isDownload.getValue())+"\t"+
                ResultFormat(this.isAnalysis.getValue())+"\t"+
                ResultFormat(this.toLink.getValue());
        return str;
    }

    //去掉一个字符串中的换行符、回车符等，将连续多个空格替换成一个空格
    public static String ResultFormat(String string){
        Pattern p = Pattern.compile("\t|\r|\n");
        Matcher m = p.matcher(string);
        string = m.replaceAll("");
        string = string.replaceAll(" +", " ");
        return string;
    }
}
